<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryBorrowRef" :inline="true" v-show="showSearch" label-width="120px">
			<el-form-item label="工单编号" prop="borrowNo">
				<el-input v-model="queryParams.borrowNo" placeholder="请输入工单编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="借阅状态" prop="giveBackStatus">
				<el-select v-model="queryParams.giveBackStatus" placeholder="请选择借阅状态">
					<el-option v-for="dict in order_give_back_status" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="借阅人姓名" prop="borrowUserName">
				<el-input v-model="queryParams.borrowUserName" placeholder="请输入借阅人姓名" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="盒号" prop="boxNo">
				<el-input v-model="queryParams.boxNo" placeholder="请输入盒号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案名称" prop="archiveName">
				<el-input v-model="queryParams.archiveName" placeholder="请输入档案名称" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案类型" prop="archiveType">
				<el-select v-model="queryParams.archiveType" placeholder="请选择档案类型">
					<el-option v-for="dict in archive_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="资料种类" prop="meansType">
				<el-select v-model="queryParams.meansType" placeholder="请选择资料种类">
					<el-option v-for="dict in means_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="对象编号" prop="archObjNo">
				<el-input v-model="queryParams.archObjNo" placeholder="请输入对象编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="对象名称" prop="archObjName">
				<el-input v-model="queryParams.archObjName" placeholder="请输入对象名称" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="借出日期" style="width:400px;">
				<el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
				 start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['archive:archiveBorrowData:export']">导出</el-button>
			</el-col>
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="archiveBorrowDataList" @selection-change="handleSelectionChange">
			<el-table-column label="序号" align='center' width="50">
				<template #default="scope">
					{{ scope.$index+1 }}
				</template>
			</el-table-column>
			<el-table-column label="借阅人供电单位编号" align="center" prop="borrowOrgNo" width="200" />
			<el-table-column label="工单编号" align="center" prop="borrowNo" width="150" />
			<el-table-column label="下发借阅状态" align="center" prop="operType" width="150">
				<template #default="scope">
					<dict-tag :options="oper_type" :value="scope.row.operType" />
				</template>
			</el-table-column>
			<el-table-column label="借阅状态" align="center" prop="giveBackStatus" width="100">
				<template #default="scope">
					<dict-tag :options="borrow_flag" :value="scope.row.giveBackStatus" />
				</template>
			</el-table-column>
			<el-table-column label="借阅人类型" align="center" prop="borrowUserType" width="100">
				<template #default="scope">
					<dict-tag :options="borrow_person_type" :value="scope.row.borrowUserType" />
				</template>
			</el-table-column>
			<el-table-column label="借阅人姓名" align="center" prop="borrowUserName" width="120" />
			<el-table-column label="联系方式" align="center" prop="borrowPhone" width="110" />
			<el-table-column label="利用方式" align="center" prop="utilizationMethod" width="80">
				<template #default="scope">
					<dict-tag :options="borrow_method" :value="scope.row.utilizationMethod" />
				</template>
			</el-table-column>
			<el-table-column label="借阅类型" align="center" prop="borrowType" width="80">
				<template #default="scope">
					<dict-tag :options="borrow_type" :value="scope.row.borrowType" />
				</template>
			</el-table-column>
			<el-table-column label="借阅天数" align="center" prop="borrowDay" width="80" />			
			<el-table-column label="借出日期" align="center" prop="borrowTime" width="160">
				<template #default="scope">
					<span>{{ parseTime(scope.row.borrowTime) }}</span>
				</template>
			</el-table-column>
			<el-table-column label="借阅原因" align="center" prop="borrowReason" width="200" />
			<el-table-column label="归还操作员" prop="giveBackBy" width="130" align="center">
			</el-table-column>
			<el-table-column label="归还时间" prop="giveBackTime" width="170" align="center">
			</el-table-column>
			<el-table-column label="实际借出日期" prop="actualBorrowTime" width="170" align="center" />
			<el-table-column label="档案区编号" width="150" align="center" prop="areaNo" />
			<el-table-column label="档案柜编号" align="center" prop="cabinetNo" width="150" />
			<el-table-column label="档案盒号" align="center" prop="boxNo" width="150" />
			<el-table-column label="档案盒位置" align="center" prop="storLoc" width="300" />
			<el-table-column label="档案名称" align="center" prop="archiveName" width="330" />
			<el-table-column label="档案类型" align="center" prop="archiveType" width="150">
				<template #default="scope">
					<dict-tag :options="archive_type" :value="scope.row.archiveType" />
				</template>
			</el-table-column>
			<el-table-column label="档案密级" align="center" prop="conLevel" width="100">
				<template #default="scope">
					<dict-tag :options="confd_lv" :value="scope.row.conLevel" />
				</template>
			</el-table-column>
			<el-table-column label="保管期限" align="center" prop="saveDate" width="100">
				<template #default="scope">
					<dict-tag :options="keep_dur" :value="scope.row.saveDate" />
				</template>
			</el-table-column>
			<el-table-column label="资料种类	" align="center" prop="meansType" width="150">
				<template #default="scope">
					<dict-tag :options="means_type" :value="scope.row.meansType" />
				</template>
			</el-table-column>
			<el-table-column label="介质类型" align="center" prop="medForm">
				<template #default="scope">
					<dict-tag :options="med_form" :value="scope.row.medForm" />
				</template>
			</el-table-column>
			<el-table-column label="对象类型" align="center" prop="archObjType" width="150">
				<template #default="scope">
					<dict-tag :options="arch_obj_type" :value="scope.row.archObjType" />
				</template>
			</el-table-column>
			<el-table-column label="对象编号" align="center" prop="archObjNo" width="150" />
			<el-table-column label="对象名称" align="center" prop="archObjName" />
		</el-table>

		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
		 @pagination="getList" />
	</div>
</template>

<script setup name="ArchiveBorrowData">
	import {
		listArchiveBorrowData,
		getArchiveBorrowData,
		delArchiveBorrowData,
		addArchiveBorrowData,
		updateArchiveBorrowData
	} from "@/api/archive/archiveBorrowData";
	import {
		getCurrentInstance,
		reactive,
		ref,
		toRefs
	} from "vue";

	const {
		proxy
	} = getCurrentInstance();
	const dateRange = ref([]);
	const archiveBorrowDataList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");

	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			// taskId: null,
			custNo: null,
			custName: null,
			// archiveType: null,
			archiveName: null,
			boxNo: null,
			// houseLocationNo: null,
			borrowNo: null,
			// flowName: null,
			// libraryStatus: null,
			giveBackStatus: null,
			pushStatus: null,
			returnPushStatus: null,
			borrowUserName: null,
			boxNo: null,
			archiveType: null,
			archiveName: null,
			meansType: null,
			medForm: null,
			archObjType: null,
			archObjNo: null,
			archObjName: null,
			
		},
		rules: {}
	});

	const {
		queryParams,
		form,
		rules
	} = toRefs(data);
	const {
		push_status,
		borrow_type,
		borrow_flag,
		borrow_person_type,
		borrow_method,
		in_out_status,
		save_year,
		secrecy_level,
		order_give_back_status,
		archive_type,
		save_extended,
		keep_dur,
		confd_lv,
		med_form,
		means_type,
		arch_obj_type,
		oper_type
	} = proxy.useDict('push_status', 'borrow_type', 'order_give_back_status', 'borrow_flag', 'borrow_person_type',
		'borrow_method', 'in_out_status', 'save_year', 'secrecy_level', 'archive_type',
		'save_extended', 'keep_dur', 'confd_lv', 'med_form', 'means_type', 'arch_obj_type','oper_type');

	/** 查询借阅信息数据列表 */
	function getList() {
		loading.value = true;
		listArchiveBorrowData(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
			// listArchiveBorrowData(queryParams.value).then(response => {
			archiveBorrowDataList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			id: null,
			taskId: null,
			custNo: null,
			custName: null,
			archiveType: null,
			archiveName: null,
			boxNo: null,
			houseLocationNo: null,
			orderNo: null,
			flowName: null,
			libraryStatus: "0",
			giveBackStatus: "0",
			boxNo: null,
			archiveType: null,
			archiveName: null,
			meansType: null,
			medForm: null,
			archObjType: null,
			archObjNo: null,
			archObjName: null,
		};
		proxy.resetForm("archiveBorrowDataRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		dateRange.value = [];
		proxy.resetForm("queryBorrowRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.id);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/archiveBorrowData/export', {
			...queryParams.value
		}, `借阅详情记录_${new Date().getTime()}.xlsx`)
	}

	getList();
</script>
